package layers;


import java.awt.Component;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JComponent;

import mapelements.Renderer;

import annotations.MainConstructor;
import annotations.ParameterType;

import tool.animation.DiscreteAnimation;

/** Il Renderer del SeaBackground.
 * @author Daniele */
public class SeaBackgroundRenderer extends Renderer {

	private static final long serialVersionUID = 2367056383535125946L;
	
	private DiscreteAnimation animation;
	
	@MainConstructor(descriptions = { "componente contenente il background" }, types = {ParameterType.COMPONENT})
	public SeaBackgroundRenderer(JComponent parent){
		super();
		try {
			this.animation = new DiscreteAnimation(null, 500);
			this.animation.addFrame(ImageIO.read(new File("fs_test/layers/WaterA.png")));
			this.animation.addFrame(ImageIO.read(new File("fs_test/layers/WaterB.png")));
			this.animation.addFrame(ImageIO.read(new File("fs_test/layers/WaterC.png")));
			this.animation.addFrame(ImageIO.read(new File("fs_test/layers/WaterB.png")));
			this.setDrawingComponent(parent);
			this.animation.start();
		}catch (IOException error){
			error.printStackTrace();
		}
	}
	
	@Override
	public BufferedImage drawRenderer(Graphics g) {
		return this.animation.paint(g);
	}

	@Override
	public SeaBackgroundRenderer clone() throws CloneNotSupportedException {
		SeaBackgroundRenderer cloned=(SeaBackgroundRenderer) super.clone();
		cloned.animation=this.animation.clone();
		return cloned;
	}

	@Override
	public void setDrawingComponent(Component parent){
		this.animation.setParent(parent);
	}
	
	@Override
	public void start(){
		this.animation.start();
	}
	
	@Override
	public void pause(){
		this.animation.pause();
	}
	
	public void restart(){
		this.animation.restart();
	}

	@Override
	public void terminate(){
		this.animation.stop();
	}

	
}
